#!/usr/bin/perl
# 
# Exercise 8.6
# 
# Write a subroutine that checks an array of data and returns true if it's in FASTA 
# format. Note that FASTA expects the standard IUB/IUPAC amino acid and nucleic 
# acid codes, plus the dash (-) that represents a gap of unknown length. Also, the 
# asterisk (*) represents a stop codon for amino acids. Be careful using an asterisk in 
# regular expressions; use a \* to escape it to match an actual asterisk.
# 
# Answer to Exercise 8.6

sub is_fasta {

	my(@contents) = @_;

	my $line = shift @contents;
	unless($line =~ /^>/) { return 0;}

	# Check if DNA
	if(grep(/[^-ACGTUMRWSYKVHDBN]/, @contents)) { return 0;}

	# Check if protein
	if(grep(/[^-ABCDEFGHIKLMNPQRSTVWXYZ\*]/, @contents)) { return 0;}

	return 1;
}
